<?php
namespace App\Services;
use App\Models\Circle;

class CircleDimSearchService {

   public static function handle($txt, $title = null) {
       if(!$title)
           $title = $txt;
       $circle_id = null;
       if (strpos($txt, '羊驼') !== false) {
           $three_circle = Circle::where('title', 'like', '%羊驼宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '龙猫') !== false) {
           $three_circle = Circle::where('title', 'like', '%龙猫宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '仓鼠') !== false) {
           $three_circle = Circle::where('title', 'like', '%仓鼠宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '刺猬') !== false) {
           $three_circle = Circle::where('title', 'like', '%刺猬宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '鹦鹉') !== false) {
           $three_circle = Circle::where('title', 'like', '%鹦鹉宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '兔') !== false) {
           $three_circle = Circle::where('title', 'like', '%兔子宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '守宫') !== false) {
           $three_circle = Circle::where('title', 'like', '%守宫宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '鱼') !== false) {
           $three_circle = Circle::where('title', 'like', '%观赏鱼宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '蛇') !== false) {
           if (strpos($txt, '猪鼻蛇') !== false) {
               $three_circle = Circle::where('title', 'like', '%猪鼻蛇宠友圈%')->orderBy('feed_count', 'desc')->first();
           } else {
               $three_circle = Circle::where('title', 'like', '%玉米蛇宠友圈%')->orderBy('feed_count', 'desc')->first();
           }
       } else if (strpos($txt, '蜜袋鼯') !== false) {
           $three_circle = Circle::where('title', 'like', '%蜜袋鼯宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '龟') !== false) {
           $three_circle = Circle::where('title', 'like', '%乌龟宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '蜘蛛') !== false) {
           $three_circle = Circle::where('title', 'like', '%蜘蛛宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else if (strpos($txt, '蜥') !== false) {
           $three_circle = Circle::where('title', 'like', '%鬃狮蜥宠友圈%')->orderBy('feed_count', 'desc')->first();
       } else {
           $cat_map = cate_map();
           if (isset($cat_map[$title]))
               $title = $cat_map[$title];

           $three_circle = Circle::where('title', 'like', '%'.$title.'%')->orderBy('feed_count', 'desc')->first();
       }
       if ($three_circle)
           $circle_id = $three_circle->id;

       return $circle_id;
   }

}
